import 'dart:ffi';
import 'dart:io';
import 'package:ffi/ffi.dart';

typedef CVoidFunctionStringParams = Void Function(Pointer<Utf8> str, Int32);
typedef DartVoidFunctionStringParams = void Function(Pointer<Utf8> str, int);
void printAndroidLogger(String log) {
  DynamicLibrary? trackLib;
  if (Platform.isAndroid) {
    trackLib = DynamicLibrary.open("libtracker-lib.so");
  }
  var func = trackLib
      ?.lookup<NativeFunction<CVoidFunctionStringParams>>("androidLogger")
      .asFunction<DartVoidFunctionStringParams>();
  String value = log;
  Pointer<Utf8> nativeValue = value.toNativeUtf8();
  func?.call(nativeValue, nativeValue.length);
  calloc.free(nativeValue);
}
